<?

//Data loading

$perush = 'PT. MASAJI PRAYASA CARGO';
$page   = 'PAGE';

$nobkt = GetParam("nobkt","");



$DEFINE_FONT=0;
$pdf=new PDFReport("P","mm","Letter"); //array("239.4","138.6")
//$pdf=new PDFReport("P","mm",array("239.4","138.6")); //array("239.4","138.6")
$pdf->AddPage();
$Result = GridList ($nobkt);
$pdf->GridTable($Result);
$pdf->Output();



function GridList ($TransNo) {
    global $DBConnection, $DBName2;

    $DBConnection = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
    
    $SQL = " SELECT * FROM ais_memorial as a
             LEFT JOIN tbldebtur as b on a.debtur = b.CUCODE
             WHERE nobkt='".$TransNo."' AND a.urut <> '999' ORDER BY urut";    
            
    return $DBConnection->dbc->get_results($SQL,ARRAY_A);
}



class PDFReport extends PDF {

function Header() {
    global $title,$title2,$perush,$page,$DEFINE_FONT,$DBConnection,$nobkt;
    if ($DEFINE_FONT==0) {
        $this->AddFont('Arial','','arialn.php');
        $DEFINE_FONT=1;
    }
         

 
   
    $this->SetFont('Arial','',16);
      
    $this->SetLeftMargin(15);  
      
	$this->Cell(180,5,"KWITANSI CASH / BANK RECEIVED",0,1,'C',0);
	$this->Ln();

    $this->SetFont('Arial','',14);
    $this->Cell(30,5,"PT. MASAJI PRAYASA CARGO",0,0,'L',0);
    $this->Ln();
    $this->SetFont('Arial','',10);
    $this->Cell(12,5,"Alamat : ",0,0,'L',0);
    $this->Cell(120,5,"JL. KALIBARU NO.4, KALIBARU, CILINCING, JAKARTA UTARA",0,0,'L',0);
    $this->SetFont('Arial','',12);
    $this->Cell(30,5,"NO: ".$nobkt,0,1,'L',0);
    $this->SetFont('Arial','',10);
    $this->Cell(12,5,"NPWP  : ",0,0,'L',0);
    $this->Cell(138,5,"01.577.508.3-046.000",0,0,'L',0);
    $this->Cell(30,5,GetOfficeLocation(),0,0,'L',0);
    $this->Ln();
	$this->Ln();
    
    $SQL = " SELECT * FROM ais_memorial as a
             LEFT JOIN tbldebtur as b on a.debtur = b.CUCODE
             WHERE nobkt='".$nobkt."' AND a.urut <> '999' ORDER BY urut";    
    $MyResults = $DBConnection->dbc->get_results($SQL,ARRAY_A);
    
	/*
    echo "<pre>";
    print_r($MyResults);
    echo "</pre>";
    */
	
    if($MyResults)
    {
    
		foreach($MyResults as $row)
		{
				$Total = $Total + $row["jumlah"];
		}
		
    }
          
    $this->Ln();

    $this->SetFont('Arial','',12);
    $this->Cell(83,5,"SUDAH TERIMA DARI / RECEIVED FROM :","T",0,'L',0);
    $this->Cell(15,5,"","TR",0,'L',0);
    $this->Cell(80,5,"ADDRESS :","T",0,'L',0);
    $this->Ln();
    $this->Cell(83,5,$MyResults[0]['debnam'],"",0,'L',0);
    $this->Cell(15,5,"","",0,'L',0);
    $this->MultiCell(80,5,$MyResults[0]['CUADDR'],"L","");
    
    

	
    $this->Cell(98,5,"Job Order : ".$MyResults[0]['jo_code'],"R",0,'L',0);
    $this->Cell(80,5,"","",0,'L',0);
    $this->Ln();
	
	$this->Cell(98,5,"Debit Note : ".$MyResults[0]['noref'],"R",0,'L',0);
    $this->Cell(80,5,"","",0,'L',0);
    $this->Ln();


    $this->Cell(50,5,"","B",0,'L',0);
    $this->Cell(3,5,"","",0,'L',0);
    $this->Cell(45,5,"","BR",0,'L',0);
    $this->Cell(80,5,"","B",0,'L',0);

    $this->Ln();

    
     

    $cc = new numtoword;    
    $SpellNumber = strtoupper(trim($cc->en($Total)));
    

    $this->Cell(178,5,"BANYAKNYA UANG ","T",0,'L',0);
    $this->Ln();
    $this->Cell(178,2,"-------------------------------- :  ".$SpellNumber." ".$Field->curr,"",0,'L',0);
    $this->Ln();
    $this->Cell(178,5,"THE SUM OF ","",0,'L',0);
    $this->Ln();

    $w=array(15,88,75);
    $this->SetFont('Arial','',12);
    $this->Cell($w[0],5,"NO.",1,0,'C',0);
    $this->Cell($w[1],5,"URAIAN / PEMBAYARAN",1,0,'C',0);
    $this->Cell($w[2],5,"JUMLAH",1,0,'C',0);
    $this->Ln();
     
    
    }
    
    
    
    

    function GridTable($MyResult) {
        //Column widths
        global $DBConnection;
        $w=array(15,88,75);
        
        list($year,$month,$day) = explode("-",$MyResult[0]['tglbkt']);
        $tglbkt  = "$day/$month/$year";
               
        if ($MyResult)
        {
				foreach($MyResult as $row)
				{
					$Total = $Total + $row["jumlah"];
					$this->Cell($w[0],5,$row["urut"].".",'LR',0,'R');
					$this->Cell($w[1],5,$row["uraian"],'LR',0,'L');
					$LatterNoArray = explode(';',trim($row["container_no"]));
					
					
					if ($row["curr"]<>"IDR") $decPoint = 2; else $decPoint = 0;
					
					$this->Cell(15,5,$row["curr"],'LR',0,'C');
					$this->Cell($w[2]-15,5,FormatNumber($row["jumlah"],$decPoint),"LR",0,R);
					
					$this->Ln();
					
					if (count($LatterNoArray)>1) {
					 for ($x=1;$x<count($LatterNoArray);$x++) {
						$this->Cell($w[0],5,"",'LR',0,'R');
						$this->Cell($w[1],5,"",'LR',0,'L');
						
								$this->Cell(10,5,"",'LR',0,'C');
								$this->Cell($w[2]-15,5,"","LR",0,R);
					  $this->Ln();
					 }
				  }

				}
        
	    }
        
            $cc = new intToRupiah;
            $GetCurrency = $DBConnection->dbc->get_var("SELECT DISTINCT tunam FROM tblcurrency, ais_advance WHERE ais_advance.nobkt='".GetParam("nobkt","")."' AND tblcurrency.tusymbol=ais_advance.curr AND ktrasl='".GetOfficeID()."'");
            //$DBConnection->dbc->debug();
            $cc->setTail($GetCurrency);
            $cc->setNumber($Total);
            $SpellNumber = ucfirst(strtoupper(trim($cc->currency)));

                $this->Cell($w[0]+$w[1],5,"TOTAL:",1,0,'R',0);
                $this->Cell($w[2],5,FormatNumber($Total,$decPoint),1,0,'R',0);
                $this->Ln();

             
                $this->Cell(50,5,"",0,0,'L',0);
                $this->Cell(140,5,"",0,0,'L',0);
                $this->Ln();
				$this->Ln();
				$this->Ln();

                //$this->Cell(15,5,"REMARK : ",0,0,'L',0);$this->Cell(50,5," ",0,0,'L',0);
				$this->Cell(15,5," ",0,0,'L',0);$this->Cell(50,5," ",0,0,'L',0);
                $this->Cell(65,5,"",0,0,'L',0);
                $this->Cell(50,5,GetBranchName().", ".$tglbkt,0,1,'C',0);

                //$this->Cell(15,5,"",0,0,'L',0);$this->MultiCell(120,5,$row["remark1"],0,1,'L',0);
             
                $this->Ln();
				$this->Ln();
				$this->Ln();
                $SQL = "SELECT * FROM $DBName.tblprofile WHERE ktrasl='".GetOfficeID()."'";
                $Result = $DBConnection->dbc->get_row($SQL);

                $this->Cell(130,5,"",0,0,'L',0);$this->Cell(50,5,"( ".$Result->ttdkw." )",0,1,'C',0);


    }

    function Footer() {
     
    }

}

?>
